package com.my.study.algorithm.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Carlos
 * @version 1.0.0
 * @date 2023/3/21 21:57
 */
public class FindDeptId {

    public static void main(String[] args) {
        Dept root = new Dept(1L, "学校");

        List<Dept> children = new ArrayList<>();
        children.add(new Dept(2L, "语文", new ArrayList<>()));
        children.add(new Dept(3L, "语文", new ArrayList<>()));
        children.add(new Dept(4L, "数学", new ArrayList<>()));

        root.setChildren(children);

        List<Long> idList = new ArrayList<>();
        getIdListFromName("语文", root, idList);
        System.out.println(idList);
    }

    private static void getIdListFromName(String name, Dept root,  List<Long> idList) {
        List<Dept> children = root.getChildren();
        if (name.equals(root.getName())) {
            idList.add(root.getId());
        }
        
        for (Dept dept : children) {
            getIdListFromName(name, dept, idList);
        }
    }

    static class OOMObject {
        private String content;

        public OOMObject(String content){
            this.content = content;
        }
    }

    static class Dept {
        private Long id;
        private String name;
        private List<Dept> children;

        public Dept() {
        }

        public Dept(Long id, String name) {
            this.id = id;
            this.name = name;
        }

        public Dept(Long id, String name, List<Dept> children) {
            this.id = id;
            this.name = name;
            this.children = children;
        }

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public List<Dept> getChildren() {
            return children;
        }

        public void setChildren(List<Dept> children) {
            this.children = children;
        }
    }
    
}
